﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Item;
using Demo_G.O.S.E.ServerEngine.Util;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Treasure
{
    /// <summary>
    /// 
    /// </summary>
    public class BaseTreasure
    {
        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        /// <param name="loot"></param>
        /// <param name="probability"></param>
        public BaseTreasure()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="loot"></param>
        /// <param name="probability"></param>
        public BaseTreasure( BaseLoot[] baseLoot, float probability )
        {
            m_Loots = baseLoot;
            m_fProbability = probability;
        }
        #endregion

        #region zh-CHS 共有属性 | en Public Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private BaseLoot[] m_Loots;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public BaseLoot[] Loots
        {
            get { return m_Loots; }
            set { m_Loots = value; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private float m_fProbability;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public float Probability
        {
            get { return m_fProbability; }
            set { m_fProbability = value; }
        }
        #endregion

        #region zh-CHS 共有静态属性 | en Public Static Properties
        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static float s_DropMultiplier = 1.0f;
        #endregion
        /// <summary>
        /// 道具掉落的几率比率
        /// </summary>
        public static float DropMultiplier
        {
            get { return BaseTreasure.s_DropMultiplier; }
            set { BaseTreasure.s_DropMultiplier = value; }
        }

        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static float s_DropGoldMultiplier = 1.0f;
        #endregion
        /// <summary>
        /// 金币掉落的几率比率
        /// </summary>
        public static float DropGoldMultiplier
        {
            get { return BaseTreasure.s_DropGoldMultiplier; }
            set { BaseTreasure.s_DropGoldMultiplier = value; }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsDrop()
        {
            if ( Utility.RandomDouble() * 100 < m_fProbability * BaseTreasure.s_DropMultiplier )
                return true;
            else
                return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lootMoney"></param>
        /// <returns></returns>
        public BaseItem[] RandomDrop()
        {
            if ( m_Loots == null )
            {
                Debug.WriteLine( "BaseTreasure.RandomDrop(...) - m_Loots == null error!" );
                return null;
            }

            List<BaseItem> treasureList = new List<BaseItem>();

            foreach ( BaseLoot loot in m_Loots )
            {
                if ( loot.IsDrop() == true )
                {
                    BaseItem baseItem = loot.Instance();
                    if ( baseItem == null )
                        Debug.WriteLine( "BaseTreasure.RandomDrop(...) - baseItem == null error!" );
                    else
                        treasureList.Add( baseItem );
                }
            }

            return treasureList.ToArray();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lootMoney"></param>
        /// <returns></returns>
        public GoldItem[] RandomGoldDrop()
        {
            if ( m_Loots == null )
            {
                Debug.WriteLine( "BaseTreasure.RandomGoldDrop(...) - m_Loots == null error!" );
                return null;
            }

            List<GoldItem> treasureList = new List<GoldItem>();

            foreach ( BaseLoot loot in m_Loots )
            {
                BaseLoot lootGold = loot as GoldLoot;
                if ( lootGold == null )
                    continue;

                if ( lootGold.IsDrop() == true )
                {
                    GoldItem goldItem = loot.Instance() as GoldItem;
                    if ( goldItem == null )
                        Debug.WriteLine( "BaseTreasure.RandomGoldDrop(...) - baseItem == null error!" );
                    else
                        treasureList.Add( goldItem );
                }
            }

            return treasureList.ToArray();
        }
        #endregion
    }
}
#endregion